//
//  ByLARInputCell.m
//  jmsfhz_ios
//
//  Created by pro on 16/7/18.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ByLARInputCell.h"

#define KViewHeight 24
#define KMargin 8

#define KBgLeftMargin SCREEN_WIDTH * 0.2 / 2
#define KBgTopMargin 5


@implementation ByLARInputCell

/** 初始化 */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.width = SCREEN_WIDTH;
        self.height = 50;

        /** 添加线 */
        [BoyeViewHandle lineCreatedInView:self.bgView fram:CGRectMake(self.markImgView.right + 10, 5, 1, self.bgView.height - 10) color:[UIColor whiteColor]];
    }
    return self;
}

/** getter */
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(KBgLeftMargin, KBgTopMargin, SCREEN_WIDTH - KBgLeftMargin * 2, self.height - KBgTopMargin * 2)];
        _bgView.backgroundColor = [UIColor colorWithWhite:0.98 alpha:1];
        _bgView.layer.cornerRadius = _bgView.height / 2;
        [self.contentView addSubview:_bgView];
    }
    return _bgView;
}
- (UIImageView *)markImgView {
    if (!_markImgView) {
        _markImgView = [[UIImageView alloc] initWithFrame:CGRectMake(KMargin, KMargin, KViewHeight, KViewHeight)];
        [self.bgView addSubview:_markImgView];
    }
    return _markImgView;
}
- (UITextField *)inputTF {
    if (!_inputTF) {
        CGFloat x = self.markImgView.right + 20;
        _inputTF = [[UITextField alloc] initWithFrame:CGRectMake(x, KMargin, self.bgView.width - KMargin - x, KViewHeight)];
        _inputTF.font = FONT(14);
        _inputTF.tintColor = JM_THEME_COLOR;
        _inputTF.backgroundColor = [UIColor clearColor];
        [self.bgView addSubview:_inputTF];

    }
    return _inputTF;
}
- (PooCodeView *)codeView {
    if (!_codeView) {
        CGFloat width = 80;
        CGFloat height = 30;
        CGFloat x = self.bgView.width - KMargin - width;
        CGFloat y = (self.bgView.height - height) / 2;
        _codeView = [[PooCodeView alloc] initWithFrame:CGRectMake(x, y, width, height)];
        _codeView.hidden = YES;
        [self.bgView addSubview:_codeView];
        self.inputTF.width -= width;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getCode)];
        [_codeView addGestureRecognizer:tap];
    }
    return _codeView;
}
- (UILabel *)codeLabel {
    if (!_codeLabel) {
        _codeLabel = [[UILabel alloc] initWithFrame:self.codeView.frame];
        _codeLabel.userInteractionEnabled = YES;
        _codeLabel.font = FONT(14);
        _codeLabel.textColor = JM_THEME_COLOR;
        _codeLabel.layer.cornerRadius = 5;
        _codeLabel.layer.borderColor = JM_THEME_COLOR.CGColor;
        _codeLabel.layer.borderWidth = 1;
        _codeLabel.backgroundColor = [UIColor clearColor];
        _codeLabel.textAlignment = NSTextAlignmentCenter;
        [self.bgView addSubview:_codeLabel];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getCode)];
        [_codeLabel addGestureRecognizer:tap];
    }
    return _codeLabel;
}

- (void)getCode {
    
    if (self.getCodeBlock) {
        self.getCodeBlock();
    }
}


@end
